﻿package Objetos 
{
	import flash.display.MovieClip;

	/**
	 * ...
	 * @author Pedro H. Machado Wigderowitz
	 */
	public class Montanha1 extends MovieClip
	{
		
		public function Montanha1() 
		{
			this.x = Math.floor( Math.random() * ( 1 + ( Main.getStage().stage.stageWidth - this.width / 2 ) - ( Main.getInstance().MC_barradeenergia.x + Main.getInstance().MC_barradeenergia. width / 2 + this.width / 2 ) ) ) + Main.getInstance().MC_barradeenergia.x + Main.getInstance().MC_barradeenergia. width / 2 + this.width / 2;
			this.y = -this.height / 2;
		}
		
		public function update(): void
		{
			this.y += Main.getInstance().UI_velocidade;
			
			if (this.y >= Main.getStage().stage.stageHeight + this.width / 2)
			{
				this.x = Math.floor( Math.random() * ( 1 + ( Main.getStage().stage.stageWidth - this.width / 2 ) - ( Main.getInstance().MC_barradeenergia.x + Main.getInstance().MC_barradeenergia. width / 2 + this.width / 2 ) ) ) + Main.getInstance().MC_barradeenergia.x + Main.getInstance().MC_barradeenergia. width / 2 + this.width / 2;
			    this.y = -this.height / 2;
			}
			
			if (Main.getInstance().MC_heroi.hitTestObject(this) && Main.getInstance().MC_heroi.y <= this.y + this.width / 2)
			{
				Main.getInstance().MC_heroi.y = this.y + this.width / 2 + Main.getInstance().MC_heroi.width / 2;
				
				Main.getInstance().MC_heroi.y += 5;
				
				Main.getInstance().SC_canalgameplay.stop();
				
				Main.getInstance().SC_canalexplosao.stop();
				Main.getInstance().SC_canalexplosao                = Main.getInstance().SO_explosao.play();
			    Main.getInstance().ST_transformarexplosao.volume   = 0.5;
			    Main.getInstance().SC_canalexplosao.soundTransform = Main.getInstance().ST_transformarexplosao;
				
				Main.getInstance().BO_gameover = true;
			}
		}
	}
}